<?php

namespace Admin\Model;
use Think\Model;

class GoodsModel extends Model {
    protected $_validate = array(
        // array(验证字段1,验证规则,错误提示,[验证条件,附加规则,验证时间]),
        array('goods_name','4,16','商品名称应是4到16个字符',1,'length',3),
        array('is_best','0,1','精品只能是0,1',0,'in',3),
        array('goods_sn','','货号不能重复',1,'unique',3),
        array('cat_id','checkCI','栏目不能为空','1','callback',3),
    );

    protected $_auto = array(
        // array(完成字段1,完成规则,[完成条件,附加规则]),
        array('add_time','time',1,'function'),
        array('last_update','time',2,'function'),
    );

    // 添加时,允许通过的字段
    protected $insertFields = 'goods_sn,cat_id,brand_id,goods_name,shop_price,market_price,goods_number,click_count,goods_weight,goods_brief,goods_desc,thumb_img,goods_img,ori_img,is_on_sale,is_delete,is_best,is_new,is_hot,add_time';
    protected $updateFields = 'goods_sn,cat_id,brand_id,goods_name,shop_price,market_price,goods_number,click_count,goods_weight,goods_brief,goods_desc,thumb_img,goods_img,ori_img,is_on_sale,is_delete,is_best,is_new,is_hot,add_time';


    protected function checkCI() {
        $cat = D('Cat');
        return $cat->find(I('post.cat_id'))?true:false;
    }
}